//
//  JudgeTextviewTableViewCell.m
//  PropertyManager
//
//  Created by TNG on 2018/7/19.
//  Copyright © 2018年 Tng. All rights reserved.
//

#import "JudgeTextviewTableViewCell.h"

@implementation JudgeTextviewTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

-(instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self creatUI];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

-(void)creatUI{
    [self.contentView addSubview:self.textview];
    [self.contentView addSubview:self.placeLabel];
    [self.contentView addSubview:self.numLabel];
}

-(UITextView *)textview
{
    if (_textview == nil) {
        _textview = [[UITextView alloc] initWithFrame:CGRectMake(20 , 15, WIDTH - 40, 180)];
        _textview.font = font(16);
        _textview.delegate = self;
        _textview.textColor = SFM153;
    }
    return _textview;
}

-(UILabel *)placeLabel
{
    if (_placeLabel == nil) {
        _placeLabel =[[UILabel alloc]initWithFrame:CGRectMake(26, 15, WIDTH - 52, 50)];
        _placeLabel.font =font(16);
        _placeLabel.textColor=SFMColor(153, 153, 153);
        _placeLabel.text = @"说说您对本次物业服务的想法，如专业水平、服务态度等是否满意。";
        _placeLabel.numberOfLines = 0;
        _placeLabel.textAlignment=NSTextAlignmentLeft;
    }
    return _placeLabel;
}

-(UILabel *)numLabel
{
    if (_numLabel == nil) {
        _numLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 195, WIDTH - 40, 20)];
        _numLabel.font = font(16);
        _numLabel.textColor = SFM153;
        _numLabel.textAlignment = NSTextAlignmentRight;
        _numLabel.attributedText = [NSMutableAttributedString headStr:@"" AndMiddleStr:@"0" AndFootStr:@" / 100" AndFont:font(16) AndTextColor:SFMColor(246, 110, 36)];
    }
    return _numLabel;
}

-(void)textViewDidChange:(UITextView *)textView
{
}

- (void)textViewDidChangeSelection:(UITextView *)textView
{
    if (textView.text.length == 0) {
        self.placeLabel.hidden = NO;
    }
    else {
        self.placeLabel.hidden = YES;
    }
    
    NSString * text = textView.text;
    if(text.length>100)
    {
        textView.text = [text substringToIndex:100];
    }
    self.numLabel.attributedText = [NSMutableAttributedString headStr:@"" AndMiddleStr:[NSString stringWithFormat:@"%d",(int)textView.text.length] AndFootStr:@" / 100" AndFont:font(16) AndTextColor:SFMColor(246, 110, 36)];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
